// controllers/fileController.js

import { successResponse, errorResponse } from "../utils/responseHelper.js";
import { uploadFile } from "../services/fileService.js";

export const uploadFileController = async (ctx) => {
  const file = ctx.request.files.file;

  if (!file) {
    ctx.body = { message: "No file uploaded" };
    console.log("No file uploaded");
    return;
  }

  try {
    const newFileRecord = await uploadFile(file);
    successResponse(ctx, newFileRecord);
  } catch (error) {
    console.log("Error processing file:", error);
    errorResponse(ctx, 500, "Error processing file");
  }
};
